/**
 * @author luguoxiang
 * @date 2022/7/5
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
import { AutoComplete, Input, Select, Switch } from 'tdesign-vue-next';
import { IConfigSchema, ITableSchema, toOptions, toStringArray } from '@/soar';

const bColumns = ['create_time', 'update_time', 'create_by', 'update_by'];
const ntColumns = [...bColumns, 'parent_id', 'left_no', 'right_no'];
const ptColumns = [...bColumns, 'parent_id', 'ancestor_link', 'sort'];

export const templates = [
  { value: 'PATH_TREE', label: 'tree（实体继承 TreeEntity）', columns: ptColumns, disabled: true },
  { value: 'NUMBER_TREE', label: 'tree（实体继承 TreeEntity）', columns: ntColumns, disabled: true },
  { value: 'BASE', label: 'base（实体继承 BaseEntity）', columns: bColumns, disabled: true },
  { value: 'NONE', label: 'none（无继承实体）', columns: [], disabled: true },
];

export const javaType = ['String', 'Integer', 'Long', 'Boolean', 'LocalDateTime', 'LocalDate', 'Date'].map((x) => ({
  value: x,
  label: x,
}));

export const webType = ['string', 'number', 'boolean', 'datetime', 'date', 'time', 'img', 'file', 'dict', 'enum'].map(
  (x) => ({ value: x, label: x }),
);

export const jsonType = [
  { value: '正常', label: '正常', annotation: '' },
  { value: '只读', label: '只读', annotation: '@JsonProperty(access = JsonProperty.Access.READ_ONLY)' },
  { value: '只写', label: '只写', annotation: '@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)' },
  { value: '忽略', label: '忽略', annotation: '@JsonIgnore' },
];

export const soarQueryField = [
  { value: '正常', label: '正常', annotation: '' },
  { value: '仅可读取', label: '仅可读取', annotation: '@SoarQueryField(whereable = false)' },
  { value: '仅可筛选', label: '仅可筛选', annotation: '@SoarQueryField(querysable = false)' },
  { value: '禁用', label: '禁用', annotation: '@SoarQueryField(whereable = false, querysable = false)' },
];

/**
 * 翻译方式
 * 字典：code（扫描数据库）
 * 枚举：枚举类型（扫描枚举），key，label（扫描属性）
 * 实体：扫描实体，key，label（扫描属性）
 * 字符串：字符串、分隔符
 */
export const transType = toStringArray('无,字典,枚举,实体,字符串').map((x) => ({ value: x, label: x }));

export const validationType = toOptions('其他,手机,邮箱,固话,手机/固话,身份证,银行卡,营业执照号');

export const filterType = toOptions(
  '不可搜索,eq,ne,lt,gt,le,ge,like,likeLeft,likeRight,notLike,in,notIn,between,notBetween,isNull,isNotNull',
);

export const columns: IConfigSchema<unknown>[] = [
  {
    label: '表名',
    field: 'TABLE_NAME',
    table: {
      sorter: true,
    },
  },
  {
    label: '表注释',
    field: 'TABLE_COMMENT',
    search: false,
  },
];

export const javaColumns: ITableSchema<unknown>[] = [
  {
    field: 'propertyName',
    label: '字段',
    width: 180,
    table: {
      edit: {
        component: Input,
        onEdited: (context) => {
          context.row.propertyName = context.newRowData.propertyName;
        },
      },
    },
  },
  {
    field: 'javaType',
    label: '数据类型',
    edit: {
      component: Select,
      props: {
        options: javaType,
      },
      onEdited: (context) => {
        context.row.javaType = context.newRowData.javaType;
      },
    },
  },
  {
    field: 'jsonType',
    label: '序列化',
    edit: {
      component: Select,
      props: {
        options: jsonType,
      },
      onEdited: (context) => {
        context.row.jsonType = context.newRowData.jsonType;
      },
    },
  },
  {
    field: 'soarQueryField',
    label: '可做条件',
    edit: {
      component: Select,
      props: {
        options: soarQueryField,
      },
      onEdited: (context) => {
        context.row.soarQueryField = context.newRowData.soarQueryField;
      },
    },
  },
  {
    field: 'comment',
    label: '描述',
    edit: {
      component: Input,
      onEdited: (context) => {
        context.row.comment = context.newRowData.comment;
      },
    },
  },
  /*  {
    field: 'transType',
    label: '翻译方式',
    edit: {
      component: Select,
      props: {
        options: transType,
      },
      onEdited: (context) => {
        context.row.transType = context.newRowData.transType;
      },
    },
  },
  {
    field: 'transName',
    label: '翻译后的字段',
    edit: {
      component: Input,
      onEdited: (context) => {
        context.row.transName = context.newRowData.transName;
      },
    },
  }, */
];

export const webColumns: ITableSchema<unknown>[] = [
  {
    field: 'field',
    label: '字段',
    width: 150,
  },
  {
    field: 'label',
    label: '标题',
    edit: {
      component: Input,
      onEdited: (context) => {
        context.row.label = context.newRowData.label;
      },
    },
    width: 180,
  },
  {
    field: 'dataType',
    label: '数据类型',
    edit: {
      component: Select,
      props: {
        options: webType,
      },
      onEdited: (context) => {
        context.row.dataType = context.newRowData.dataType;
      },
    },
    width: 150,
  },
  {
    field: 'params',
    label: '类型参数',
    edit: {
      component: Input,
      onEdited: (context) => {
        context.row.params = context.newRowData.params;
      },
    },
  },
  /*  {
    field: 'table',
    label: '列表',
    slots: 'table',
  },
  {
    field: 'search',
    label: '搜索',
    slots: 'search',
  },
  {
    field: 'form',
    label: '表单',
    slots: 'form',
  },
  {
    field: 'detail',
    label: '详情',
    slots: 'detail',
  }, */
];
